package com.nf.health.app.myfamily.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.adapter.AccountAdapter;
import com.nf.health.app.adapter.OnMyClickListener;
import com.nf.health.app.models.Account;
import com.nf.health.app.utils.ViewUtil;

import java.util.List;

/** 
 * @ClassName: CancelBindingActivity 
 * @Description: 取消绑定页面
 * @author Ian 
 * @date 2015-11-4 上午9:40:18 
 *  
 */
public class CancelBindingActivity extends BaseActivity implements OnMyClickListener {

	private ListView listview;
	private List<Account> accounts;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setTitleBar(R.layout.titlebar_base);
		setContent(R.layout.activiyt_cancel_binding);

		ViewUtil.setText(this, R.id.titlebar_title_tv, "取消绑定");
		listview = ViewUtil.getView(this, R.id.listview);

		initData();
	}

	private void initData() {
		provider.requestBindAccount("bindAccount");		
	}

	@SuppressWarnings("unchecked")
	@Override
	public void handleActionSuccess(String actionName, Object object) {
		if("bindAccount".equals(actionName)){
			accounts = (List<Account>) object;
			AccountAdapter adapter = new AccountAdapter(accounts);
			adapter.setMyOnClickListener(this);
			listview.setAdapter(adapter);
		}else if("unBindBox".equals(actionName)){
			//TODO
			initData();
		}else if("unBindAppAccount".equals(actionName)){
			//TODO
			initData();
		}else if("unBindOldAccount".equals(actionName)){
			//TODO
			initData();
		}else if("unBinddoctorAccount".equals(actionName)){
			//TODO
			initData();
		}
	}

	@Override
	public void onClick(int position, String flag) {
		Account account = accounts.get(position);
		if("family".equals(account.getType())){
			provider.requestUnBindBox(account.getTouserid(),"unBindBox");
		}
		if("simple".equals(account.getType())){
			provider.requestUnBindAppAccount(account.getTouserid(),"unBindAppAccount");
		}

		if("oldMobile".equals(account.getType())){
			provider.requestUnBindOld(account.getTouserid(),"unBindOldAccount");

		}
		if("doctor".equals(account.getType())){
			provider.requestUnBindOld(account.getTouserid(),"unBinddoctorAccount");

		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.titlebar_back_view:
			setResult(RESULT_OK);
			finish();
			break;

		default:
			break;
		}
	}
}
